package com.jhhc.StormSurgeForecast.AstronomicalTide.ServiceImpl;

import com.jhhc.StormSurgeForecast.AstronomicalTide.Pojo.BDMS_FBC_STRMSRG_HARINFO;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.PageRequest;

import javax.annotation.Resource;
import java.util.List;

/**
 * (BdmsFbcStrmsrgHarinfo)表服务实现类
 *
 * @author makejava
 * @since 2023-03-25 18:46:26
 */
@Service
public class BDMS_FBC_STRMSRG_HARINFOServiceImpl implements com.jhhc.StormSurgeForecast.AstronomicalTide.Service.BDMS_FBC_STRMSRG_HARINFOService {
    @Resource
    private com.jhhc.StormSurgeForecast.AstronomicalTide.Dao.BDMS_FBC_STRMSRG_HARINFOMapper BDMSFBCSTRMSRGHARINFOMapper;


    @Value("${datasourceType}")
    String datasourceType;
    /**
     * 通过ID查询单条数据
     *
     * @param pid 主键
     * @return 实例对象
     */
    @Override
   public List<BDMS_FBC_STRMSRG_HARINFO> queryById(Integer pid, String stcd, Integer year){
        if ("mysql".equals(datasourceType)){
          return   BDMSFBCSTRMSRGHARINFOMapper.queryById(pid, stcd, year);
        }else if ("sqlserver".equals(datasourceType)){
            return BDMSFBCSTRMSRGHARINFOMapper.queryByIdSqlserver(pid, stcd, year);
        }

      return   null;
    }

    @Override
    public BDMS_FBC_STRMSRG_HARINFO queryByCreateTime(Integer pid, String stcd, Integer year, String createTime) {
        if ("mysql".equals(datasourceType)){
            return   BDMSFBCSTRMSRGHARINFOMapper.queryByCreateTime(pid, stcd, year,createTime);
        }else if ("sqlserver".equals(datasourceType)){
            return BDMSFBCSTRMSRGHARINFOMapper.queryByCreateTimeSqlserver(pid, stcd, year,createTime);
        }

        return   null;
    }


    /**
     * 分页查询
     *
     * @param BDMSFBCSTRMSRGHARINFO 筛选条件
     * @param pageRequest      分页对象
     * @return 查询结果
     */
    @Override
    public Page<BDMS_FBC_STRMSRG_HARINFO> queryByPage(BDMS_FBC_STRMSRG_HARINFO BDMSFBCSTRMSRGHARINFO, PageRequest pageRequest) {
        long total = this.BDMSFBCSTRMSRGHARINFOMapper.count(BDMSFBCSTRMSRGHARINFO);
        return new PageImpl<>(this.BDMSFBCSTRMSRGHARINFOMapper.queryAllByLimit(BDMSFBCSTRMSRGHARINFO, pageRequest), pageRequest, total);
    }

    /**
     * 新增数据
     *
     * @param BDMSFBCSTRMSRGHARINFO 实例对象
     * @return 实例对象
     */
    @Override
    public int  insert(BDMS_FBC_STRMSRG_HARINFO BDMSFBCSTRMSRGHARINFO) {
        if ("mysql".equals(datasourceType)){
            return   BDMSFBCSTRMSRGHARINFOMapper.insert(BDMSFBCSTRMSRGHARINFO);
        }else if ("sqlserver".equals(datasourceType)){
            return BDMSFBCSTRMSRGHARINFOMapper.insertSqlServer(BDMSFBCSTRMSRGHARINFO);
        }
        return  0;
    }

    @Override
    public BDMS_FBC_STRMSRG_HARINFO update(BDMS_FBC_STRMSRG_HARINFO BDMSFBCSTRMSRGHARINFO) {
        return null;
    }

    /**
     * 修改数据
     *
     * @param BDMSFBCSTRMSRGHARINFO 实例对象
     * @return 实例对象
     */


    /**
     * 通过主键删除数据
     *
     * @param pid 主键
     * @return 是否成功
     */
    @Override
  public   int deleteById(Integer pid,String year,String stcd){

        if ("mysql".equals(datasourceType)){
            return   BDMSFBCSTRMSRGHARINFOMapper.deleteById(pid, year, stcd);
        }else if ("sqlserver".equals(datasourceType)){
            return BDMSFBCSTRMSRGHARINFOMapper.deleteByIdSqlServer(pid, year,stcd);
        }
        return  0;
    }
}
